/* Console.h
Copyright (c) 2008 Michael Zahniser
Please note the license terms (MIT license) at the end of this document.

Headerfile for the kwirki Console class, defining a console (ncurses)
view and editor of the wiki pages.
*/

#ifndef __KWIRKI_CONSOLE_H__
#define __KWIRKI_CONSOLE_H__

#include "Editor.h"

#include "_common/ViewProperties.h"
#include "_common/wrap.h"

#include <list>

using std::list;



class Console {
public:
	// The constructor starts ncurses.
	Console();
	// The destructor ends ncurses and restores the terminal to normal.
	~Console();
	
	// Open the given file for editing.
	// If another file is open, the file will be opened on a "stack"
	// with the previous file still open underneath it. This is how
	// browsing history is implemented, and allows the full scroll
	// state of each file to be saved when visiting a new one.
	// If we already have a copy of the file open, just move that
	// copy's editor to the top of the list.
	void Edit(const string &fileName);
	
	// Run the event loop.
	void Run();
	
	
private:
	// Update the view.
	void Draw() const;
	
	
private:
	CountChars<text> textMeasure;
	ViewProperties<text> viewProperties;
	
	// These are all the editors we have open.
	list<Editor *> editors;
	list<Editor *>::iterator editor;
};



#endif



/* Copyright (c) 2008 Michael Zahniser

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. */

